package com.example.fashionshoes.service.coupon;

import com.example.fashionshoes.exception.BusinessException;
import com.example.fashionshoes.pojo.po.Coupon;

import java.math.BigDecimal;

/**
 * 满减优惠劵,包括无门槛
 */
public class FullMinusCoupon implements CouponStrategy {
    @Override
    public BigDecimal useCoupon(BigDecimal price, Coupon coupon) throws BusinessException {
        BigDecimal minPoint = coupon.getMinPoint();
        BigDecimal amount = coupon.getAmount();
        //指定商品
        if (coupon.getUseType().equals(2)) {
            if (minPoint.compareTo(price) > 0) {
                throw new BusinessException("未达到要求");
            }
        }
        //优惠劵面额大于商品价格，统一收取0.01
        if (coupon.getAmount().compareTo(price) >0){
            //TODO 扣减优惠劵面额而不是使用
            return new BigDecimal("0.01");
        }
        return price.subtract(amount);
    }
}
